using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;

public partial class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString fnRegEx_Replace(string inputValue, string searchPattern, string replacePattern)
    {
        if (inputValue == null || searchPattern == null)
            return null;

        if (System.Text.RegularExpressions.Regex.IsMatch(inputValue, searchPattern, Options))
            return System.Text.RegularExpressions.Regex.Replace(inputValue, searchPattern, replacePattern);
        else
            return null;
    }
}
